<?php
/**
 * 设计师违规，到期结束开始相关，用于监测违规变化
 */
use Doraemon\tools\Log;
use Doraemon\model\Designer;
use Doraemon\service\DesignerService\WholeHouse as sWholeHouse;
use Doraemon\service\DesignerService\XinXuanDecoration as sXinXuanDecoration;

class ViolationAction extends ActionPlugin {

    public function main()
    {
        Log::info('设计师违规监测变化开始接收到事件信息', $this->messageBody);
        $message = $this->messageBody;
        $table = $this->messageBody['table'] ?? '';
        $uid = 0;
        if (strstr($table, Designer::_TABLE_NAME)) {
            $uid = $this->messageBody['data']['uid'] ?? 0;
            $eventType = $this->messageBody['type'] ?? '';
            $oldPunishTypeList = $this->messageBody['old']['violation_type'];
            $curPunishTypeList = $this->messageBody['data']['violation_type'];
            if ($eventType == 'update') {
                $curPunishTypeList = explode(' ', $curPunishTypeList);
                $oldPunishTypeList = explode(' ', $oldPunishTypeList);
                $diffPunishTypeList = array_merge(array_diff($oldPunishTypeList, $curPunishTypeList), array_diff($curPunishTypeList, $oldPunishTypeList));
                if (!empty($diffPunishTypeList)) {
                    // 处理全屋设计H5用户展示状态字段
                    sWholeHouse::syncShowStatus($uid);

                    // 处理装修搭子H5用户展示状态字段
                    sXinXuanDecoration::syncShowStatusDesigner($uid);
                }
            }
        }
        Log::info('设计师违规监测变化结束接收到的事件', compact('uid', 'message'));
        $this->setSuccess();
    }
}